import request from '@/utils/request'
import { VITE_APP_UPLOAD_URL} from '@/api/upload'

// 根据id获取附件详情
export function getFiles(id) {
  return request({
    url: `/file/sysAttMain/getByModuleId/${id}`,
    method: 'get',
  })
}
export function getFilesByModuleKey(id,moduleKey) {
  return request.get('/file/sysAttMain/getByModuleKey', {
    params:{
      moduleId:id,
      moduleKey:moduleKey,
    }
  })
}
export function getByModuleIdModuleKeyAndUserId(id,moduleKey, userId) {
  console.log(userId)
  return request.get('/file/sysAttMain/getByModuleIdModuleKeyAndUserId', {
    params:{
      moduleId:id,
      moduleKey:moduleKey,
      userId:userId
    }
  })
}
// 根据id获取我的附件详情
export function getMyFiles(id) {
  return request({
    url: `/file/sysAttMain/getMyFileByModuleId/${id}`,
    method: 'get',
  })
}
// 根据id获取我的附件详情
export function getFilesByUserId(id,userId) {
  return request.get('/file/sysAttMain/getFileByModuleIdAndUserId', {
    params:{
      moduleId:id,
      userId:userId,
    }
  })
}

// 根据id删除对应附件
export function deleteFile(id) {
  return request({
    url: `/file/sysAttMain/delete/${id}`,
    method: 'post',
  })
}

// 根据id下载对应附件
export function downloadFile(id) {
  return request({
    url: `/file/sysAttMain/download/${id}`,
    method: 'post',
    responseType: 'blob' // 获取文件流格式blob的响应对象
  })
}

export function uploadFile(data) {
  return request.post(VITE_APP_UPLOAD_URL.replace("/prod-api",'').replace('upload','richTextupload'), data, {headers: {'Content-Type': 'multipart/form-data'}})
}
